package com.atguigu.spzx.manager.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.sys.SysRole;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2023-11-03-18:21
 */
@RestController
@RequestMapping("/admin/system/role")
@Tag(name = "Role模块")
public class SysRoleController {

    @Resource
    SysRoleService sysRoleService;

    @Operation(summary = "分页查询接口",description = "分页查询接口")
    @Parameters(value = {
            @Parameter(name = "pageNum",description = "页码参数",
                    in = ParameterIn.HEADER,required = true),
            @Parameter(name = "pageSize",description = "页面显示条数参数",
                    in = ParameterIn.HEADER,required = true),
            @Parameter(name = "keyword",description = "页面模糊参数",
                    in = ParameterIn.HEADER,required = false)
    })
    @GetMapping("/page/{pageNum}/{pageSize}")
    public Result getPage(@PathVariable Integer pageNum,
                          @PathVariable Integer pageSize,
                          String keyword
    ) {
        PageInfo<SysRole> pageInfo = sysRoleService.getPage(pageNum,pageSize,keyword);
        return Result.ok().data(pageInfo);
    }
    @Operation(summary = "删除接口",description = "删除接口")
    @Parameters(value = {
            @Parameter(name = "id",description = "role表id字段参数",
                    in = ParameterIn.HEADER,required = true)
    })
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        sysRoleService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "根据id查询单条数据接口",description = "根据id查询单条数据接口")
    @Parameters(value = {
            @Parameter(name = "id",description = "role表id字段参数",
                    in = ParameterIn.HEADER,required = true)
    })
    @GetMapping("/GetRoleById/{id}")
    public Result GetRoleById(@PathVariable Integer id){
      SysRole sysRole = sysRoleService.GetRoleById(id);
      return Result.ok().data(sysRole);
    }
    @Operation(summary = "修改数据接口",description = "修改数据接口")
    @Parameters(value = {
            @Parameter(name = "role",description = "SysRole参数模型",
                    in = ParameterIn.HEADER,required = true)
    })
    @PutMapping("/UpdateRoleById")
    public Result UpdateRoleById (@RequestBody SysRole role){
        sysRoleService.UpdateRoleById(role);
        return Result.ok();
    }
    @Operation(summary = "添加数据接口",description = "添加数据接口")
    @Parameters(value = {
            @Parameter(name = "role",description = "SysRole参数模型",
                    in = ParameterIn.HEADER,required = true)
    })
    @PostMapping("/save")
    public Result saveRole(@RequestBody SysRole role){
        sysRoleService.saveRole(role);
        return Result.ok();
    }

    @GetMapping("/getRole/{id}")
    public Result getRole(@PathVariable Long id){
        List<SysRole> roles = sysRoleService.getRole(id);
        return Result.ok().data(roles);
    }


}
